//应收款统计图表的配置项和数据
var option1 = {
	xAxis : {
		type : 'time',
		name : '时间',
		nameLocation : 'middle',
		nameGap:45,
		interval : 3600 * 24 * 1000 * 30,
		splitLine:{
			show:false
		}
 	},
	tooltip : {
		trigger : 'axis',
		axisPointer : {
			animation : false
		}
	},
	yAxis : {
		type : 'value',
		name : '工位收入统计',
		nameGap:50,
		nameLocation : 'middle',
		axisLabel : {
			formatter : '{value}'
		}
	},
	series : [ {
		type : 'line',
		smooth : true,
		data : [ [ '2017/08/01', 20 ], [ '2017/08/03', 32 ], [ '2017/08/04', 20 ], [ '2017/08/05', 40 ] ]
	} ]
};



var paramsUsageRate = {// 会议室使用统计查询参数
	projectId : $("#projectId", top.document).val(),
};
$(function() {
	layui.use([ 'form', 'laydate' ], function() {
		var laydate = layui.laydate, form = layui.form;

		// 初始化分店下拉
		initFormSelectsExt({// 分店ffff
			id : "project",
			url : '/app/customerInfo/getProjectJson',
			defaultValue : paramsUsageRate.projectId,
			first : "*" // 代表没有默认提示项
		});

		laydate.render({
			elem : 'input.usageRateDate', // 指定元素
			// value: staDate+' ~ '+endDate,
			range : '~',
			done : function(value, date, endDate) {
				var rangeDate = value.split(' ~ ');
				paramsUsageRate.staDate = rangeDate[0];
				paramsUsageRate.endDate = rangeDate[1];
				initChart1();
			}
		});
		form.on('select(dateTl)', function(data) {
			$("input.usageRateDate").val("");
			if(data.value == ""){
				paramsUsageRate.startdate = null;
				paramsUsageRate.enddate = null;
			}else{
				var now = new Date();
				// 以当前时间为结束时间 计算区间
				var enddate = now.format('yyyy-MM-dd');
				now.setMonth(now.getMonth() - data.value);
				var startdate = now.format('yyyy-MM-dd');
	
				paramsUsageRate.startdate = startdate;
				paramsUsageRate.enddate = enddate;
			}
			initChart1();
		});
		form.on('select(project)', function(data) {
			paramsUsageRate.projectId = data.value;
			initChart1();
		});
	});
	// 初始化各个图表
	initChart1();
});
function initChart1() {
	var myChart1 = echarts.init(document.getElementById('receibaletj'));
	$.post("/app/statistical/receivableData", {
		params : paramsUsageRate
	}, function(data) {
		option1.series[0].data = convDouArray(data);
		// 使用刚指定的配置项和数据显示图表。
		myChart1.setOption(option1);
	});
}



/* 将一维数组([{x:1,y:2},{x:1,y:2},{x:1,y:2}])转换成二维数组([[1,2],[1,2],[1,2]]) */
function convDouArray(data) {
	var array = new Array();
	for (var i = 0; i < data.length; i++) {
		array.push([ data[i].x, parseFloat(data[i].y) ]);
	}
	return array;
}